//    Copyright (C) Kherty.  All rights reserved.
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace OpenLS.Chart.UI.Internals
{
    sealed class RichTextBoxHelper: FrameworkElement
    {


        public static FlowDocument GetFlowDocument(DependencyObject obj)
        {
            return (FlowDocument)obj.GetValue(FlowDocumentProperty);
        }

        public static void SetFlowDocument(DependencyObject obj, FlowDocument value)
        {
            obj.SetValue(FlowDocumentProperty, value);
        }

        // Using a DependencyProperty as the backing store for FlowDocument.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FlowDocumentProperty =
            DependencyProperty.RegisterAttached("FlowDocument", typeof(FlowDocument), typeof(RichTextBoxHelper), new UIPropertyMetadata(null, onPropertyChanged));

        private static void onPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox rtb = (RichTextBox) d;
            if (e.NewValue == null)
            {
                rtb.Document = new FlowDocument();
            }
            rtb.Document = (FlowDocument) e.NewValue;

        }
    }
}
